/**
*      author: Y_Yao
*      created: 2025-04-09 22:01:42
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 9e18;
const int INF = 0x3f3f3f3f;
int n;
unordered_map<int,priority_queue<int>> mp;

void solve()
{
    cin >> n;
    for(int i = 1;i <= n;i++)
    {
        int f,s;
        cin >> f >> s;
        mp[f].push(s);
    }

    int ans1 = 0,ans2 = 0;
    int mx1 = 0,mx2 = 0;
    for(auto& e : mp)
    {
        mx1 = max(mx1,e.second.top());
    }
    int cnt = 0;
    for(auto& e : mp)
    {
        if(e.second.top() == mx1)
        {
            cnt++;
            continue;
        }
        mx2 = max(mx2,e.second.top());
    }
    if(cnt >= 2)
    {
        mx2 = mx1;
    }
    ans1 = mx1 + mx2;

    for(auto& e : mp)
    {
        auto& cur = e.second;
        if(e.second.size() >= 2)
        {
            int a = cur.top();
            cur.pop();
            int b = cur.top();
            cur.pop();
            ans2 = max(ans2,max(a,b) + min(a,b) / 2);
        }
    }
    cout << max(ans1,ans2) << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    // cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}